package managedbean.SCM.PackingOrder;

import entity.SCM.PackingOrder;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.SCM.DeliveryOrderBeanLocal;

@ManagedBean (name = "pendingPackingOrderManagerBean")
@ViewScoped
public class PendingPackingOrderManagerBean implements Serializable{

    public PendingPackingOrderManagerBean() {
    }
    
    @EJB
    private DeliveryOrderBeanLocal deliveryOrderBeanLocal;
    private PackingOrder selectedPackingOrder;
    private String statusMessage;

    public PackingOrder getSelectedPackingOrder() {
        return selectedPackingOrder;
    }

    public void setSelectedPackingOrder(PackingOrder selectedPackingOrder) {
        this.selectedPackingOrder = selectedPackingOrder;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public List<PackingOrder> getPendingPackingOrder(){
        return deliveryOrderBeanLocal.getPendingPackingOrder();
    }
    
    public void processPackingOrder(ActionEvent event){
        try{
            
            boolean success = deliveryOrderBeanLocal.processPackingOrder(selectedPackingOrder.getId());
            
            if(!success){
                statusMessage = "Please Try Again.";
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Unsuccessful:" + statusMessage + "", ""));
            }else{
                statusMessage = "Process Packing Order Successfully.";
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, statusMessage, ""));
            }
            
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
